home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / byte0787.arc / NEWGEN.ARC / WHET.C < prev   
Encoding:
C/C++ Source or Header  |  1987-04-21  |  6.1 KB  |  296 lines

  1. /*
  2. From hplabs!sdcrdcf!sdcsvax!dcdwest!ittatc!decvax!mcnc!rti-sel!scirtp!dfh Sun Aug 25 12:55:29 1985
  3. Relay-Version: version B 2.10.2 9/18/84; site amdahl.UUCP
  4. Posting-Version: version B 2.10.2 9/5/84; site scirtp.UUCP
  5. Path: amdahl!hplabs!sdcrdcf!sdcsvax!dcdwest!ittatc!decvax!mcnc!rti-sel!scirtp!dfh
  6. From: dfh@scirtp.UUCP (David F. Hinnant)
  7. Newsgroups: net.sources
  8. Subject: Whetstone Benchmark source in C - enclosed
  9. Message-ID: <353@scirtp.UUCP>
  10. Date: 25 Aug 85 19:55:29 GMT
  11. Date-Received: 27 Aug 85 08:15:18 GMT
  12. Distribution: net
  13. Organization: SCI Systems, Research Triangle Park, NC
  14. Lines: 252
  15.  
  16. Enclosed below is a C translation of the famous "Whetstone Benchmark"
  17. from the original Algol version.  I have inserted printf()'s as a
  18. compiler option.  I think this translation is accurate.  The only
  19. numbers I have to compare with are from an old Ridge-32 machine, and
  20. these are from a Pascal translation (I caught one error in their
  21. translation).  If anyone has any nunbers from FORTRAN, Pascal, or Algol
  22. versions of the Whetstone, I would very much like to see them.
  23.  
  24.                 David Hinnant
  25.                 SCI Systems, Inc.
  26.                 {decvax, akgua}!mcnc!rti-sel!scirtp!dfh
  27.  
  28.  
  29. P.s., there is a .signature file at the end of the listing. */
  30.  
  31. //===========================================================================
  32. /*
  33.  *      Whetstone benchmark in C.  This program is a translation of the
  34.  *    original Algol version in "A Synthetic Benchmark" by H.J. Curnow
  35.  *      and B.A. Wichman in Computer Journal, Vol  19 #1, February 1976.
  36.  *
  37.  *    Used to test compiler optimization and floating point performance.
  38.  *
  39.  *    Compile by:        cc -O -s -o whet whet.c
  40.  *    or:            cc -O -DPOUT -s -o whet whet.c
  41.  *    if output is desired.
  42.  */
  43.  
  44. #define ITERATIONS    10 /* 1 Million Whetstone instructions */
  45.  
  46. #include "sane.h"
  47. #include "stdio.h"
  48.  
  49. // #Options G H
  50.  
  51. #define POUT
  52. #define Pout(n, j, k, x1, x2, x3, x4) timingOff;\
  53. pout(n, j, k, x1, x2, x3, x4);timingOn
  54. #define double extended
  55. #define tickCount *((long *)0x16A)
  56. #define timingOn ticks -= tickCount
  57. #define timingOff ticks += tickCount
  58.  
  59.  
  60. double        xx1, xx2, xx3, xx4, x, y, z, t, t1, t2;
  61. double         e1[4];
  62. int        i, j, k, l, n1, n2, n3, n4, n6, n7, n8, n9, n10, n11;
  63. long         ticks;
  64.  
  65. main()
  66. {
  67.     printf("\nWhetstone Benchmark\n\n");
  68.     
  69.     ticks = 0;
  70.     
  71.     timingOn;
  72.  
  73.     /* initialize constants */
  74.        
  75.     t   =   0.499975;
  76.     t1  =   0.50025;
  77.     t2  =   2.0;
  78.  
  79.     /* set values of module weights */
  80.  
  81.     n1  =   0 * ITERATIONS;
  82.     n2  =  12 * ITERATIONS;
  83.     n3  =  14 * ITERATIONS;
  84.     n4  = 345 * ITERATIONS;
  85.     n6  = 210 * ITERATIONS;
  86.     n7  =  32 * ITERATIONS;
  87.     n8  = 899 * ITERATIONS;
  88.     n9  = 616 * ITERATIONS;
  89.     n10 =   0 * ITERATIONS;
  90.     n11 =  93 * ITERATIONS;
  91.  
  92. /* MODULE 1:  simple identifiers */
  93.  
  94.     xx1 =  1.0;
  95.     xx2 = xx3 = xx4 = -1.0;
  96.  
  97.     for(i = 1; i <= n1; i += 1) {
  98.         xx1 = ( xx1 + xx2 + xx3 - xx4 ) * t;
  99.         xx2 = ( xx1 + xx2 - xx3 - xx4 ) * t;
  100.         xx3 = ( xx1 - xx2 + xx3 + xx4 ) * t;
  101.         xx4 = (-xx1 + xx2 + xx3 + xx4 ) * t;
  102.     }
  103. #ifdef POUT
  104.     Pout(n1, n1, n1, xx1, xx2, xx3, xx4);
  105. #endif
  106.  
  107.  
  108. /* MODULE 2:  array elements */
  109.  
  110.     e1[0] =  1.0;
  111.     e1[1] = e1[2] = e1[3] = -1.0;
  112.  
  113.     for (i = 1; i <= n2; i +=1) {
  114.         e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
  115.         e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
  116.         e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
  117.         e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
  118.     }
  119. #ifdef POUT
  120.     Pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
  121. #endif
  122.  
  123. /* MODULE 3:  array as parameter */
  124.  
  125.     for (i = 1; i <= n3; i += 1)
  126.         pa(e1);
  127. #ifdef POUT
  128.     Pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
  129. #endif
  130.  
  131. /* MODULE 4:  conditional jumps */
  132.  
  133.     j = 1;
  134.     for (i = 1; i <= n4; i += 1) {
  135.         if (j == 1)
  136.             j = 2;
  137.         else
  138.             j = 3;
  139.  
  140.         if (j > 2)
  141.             j = 0;
  142.         else
  143.             j = 1;
  144.  
  145.         if (j < 1 )
  146.             j = 1;
  147.         else
  148.             j = 0;
  149.     }
  150. #ifdef POUT
  151.     Pout(n4, j, j, xx1, xx2, xx3, xx4);
  152. #endif
  153.  
  154. /* MODULE 5:  omitted */
  155.  
  156. /* MODULE 6:  integer arithmetic */
  157.  
  158.     j = 1;
  159.     k = 2;
  160.     l = 3;
  161.  
  162.     for (i = 1; i <= n6; i += 1) {
  163.         j = j * (k - j) * (l -k);
  164.         k = l * k - (l - j) * k;
  165.         l = (l - k) * (k + j);
  166.  
  167.         e1[l - 2] = j + k + l;        /* C arrays are zero based */
  168.         e1[k - 2] = j * k * l;
  169.     }
  170. #ifdef POUT
  171.     Pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
  172. #endif
  173.  
  174. /* MODULE 7:  trig. functions */
  175.  
  176.     x = y = 0.5;
  177.  
  178.     for(i = 1; i <= n7; i +=1) {
  179.         x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
  180.         y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
  181.     }
  182. #ifdef POUT
  183.     Pout(n7, j, k, x, x, y, y);
  184. #endif
  185.  
  186. /* MODULE 8:  procedure calls */
  187.  
  188.     x = y = z = 1.0;
  189.  
  190.     for (i = 1; i <= n8; i +=1)
  191.         p3(x, y, &z);
  192. #ifdef POUT
  193.     Pout(n8, j, k, x, y, z, z);
  194. #endif
  195.  
  196. /* MODULE9:  array references */
  197.  
  198.     j = 1;
  199.     k = 2;
  200.     l = 3;
  201.  
  202.     e1[0] = 1.0;
  203.     e1[1] = 2.0;
  204.     e1[2] = 3.0;
  205.  
  206.     for(i = 1; i <= n9; i += 1)
  207.         p0();
  208. #ifdef POUT
  209.     Pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
  210. #endif
  211.  
  212. /* MODULE10:  integer arithmetic */
  213.  
  214.     j = 2;
  215.     k = 3;
  216.  
  217.     for(i = 1; i <= n10; i +=1) {
  218.         j = j + k;
  219.         k = j + k;
  220.         j = k - j;
  221.         k = k - j - j;
  222.     }
  223. #ifdef POUT
  224.     Pout(n10, j, k, xx1, xx2, xx3, xx4);
  225. #endif
  226.  
  227. /* MODULE11:  standard functions */
  228.  
  229.     x = 0.75;
  230.     for(i = 1; i <= n11; i +=1)
  231.         x = sqrt( exp( log(x) / t1));
  232.  
  233. #ifdef POUT
  234.     Pout(n11, j, k, x, x, x, x);
  235. #endif
  236.   
  237.   timingOff;
  238.   printf("\nWhetstone runs in %0.2f seconds. %0.2f whets/second\n", 
  239.           ticks/60.0, 60000000.0/ticks);
  240.   getchar();
  241.   exit(0);
  242.  
  243. }
  244.  
  245. pa(e)
  246. double e[4];
  247. {
  248.     register int j;
  249.  
  250.     j = 0;
  251.      lab:
  252.     e[0] = (  e[0] + e[1] + e[2] - e[3] ) * t;
  253.     e[1] = (  e[0] + e[1] - e[2] + e[3] ) * t;
  254.     e[2] = (  e[0] - e[1] + e[2] + e[3] ) * t;
  255.     e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
  256.     j += 1;
  257.     if (j < 6)
  258.         goto lab;
  259. }
  260.  
  261.  
  262. p3(x, y, z)
  263. double x, y, *z;
  264. {
  265.     x  = t * (x + y);
  266.     y  = t * (x + y);
  267.     *z = (x + y) /t2;
  268. }
  269.  
  270.  
  271. p0()
  272. {
  273.     e1[j] = e1[k];
  274.     e1[k] = e1[l];
  275.     e1[l] = e1[j];
  276. }
  277.  
  278. #ifdef POUT
  279. pout(n, j, k, x1, x2, x3, x4)
  280. int n, j, k;
  281. double x1, x2, x3, x4;
  282. {
  283.     printf("%5d %5d %5d   %11.3e %11.3e %11.3e %11.3e\n",
  284.         n, j, k, x1, x2, x3, x4);
  285. }
  286. #endif
  287.  
  288. /*
  289. =======================================================================
  290. -- 
  291.                 David Hinnant
  292.                 SCI Systems, Inc.
  293.                 {decvax, akgua}!mcnc!rti-sel!scirtp!dfh
  294.  
  295. */